//
//  HMSelectTitleView.m
//  HMMarket
//
//  Created by maimaigo3 on 2017/5/16.
//  Copyright © 2017年 homai. All rights reserved.
//

#import "HMSelectTitleView.h"
#import "HomeCategory.h"
@interface HMSelectTitleView ()<UIActionSheetDelegate>

NS_STRONG UIImageView *imageVI;

NS_STRONG UIButton *titleButton;

@end


@implementation HMSelectTitleView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpSubView];
    }
    return self;
}

- (void)setUpSubView {
    
    _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _titleButton.frame = CGRectMake(0, 0, 60, 40);
    [_titleButton addTarget:self action:@selector(selectType) forControlEvents:UIControlEventTouchUpInside];
    [_titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_titleButton setTitle:@"蔬菜" forState:UIControlStateNormal];
    _titleButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [self addSubview:_titleButton];
    
    _imageVI = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_titleButton.frame), 15, 15, 10)];
    _imageVI.userInteractionEnabled = YES;
    _imageVI.image = [UIImage imageNamed:@"ProductList_click_down"];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectType)];
    [_imageVI addGestureRecognizer:tap];
    _imageVI.userInteractionEnabled = YES;
    [self addSubview:_imageVI];
}

- (void)setSelectCardType:(NSInteger)selectCardType {
    _selectCardType = selectCardType;
}

- (void)selectType {
    _upAndDown = !_upAndDown;
    if (_upAndDown) {
        _imageVI.image = [UIImage imageNamed:@"ProductList_click_up"];
        if ([_delegate respondsToSelector:@selector(changeType:)]) {
            [_delegate changeType:CLICK_UP];
        }
    } else {
        _imageVI.image = [UIImage imageNamed:@"ProductList_click_down"];
        if ([_delegate respondsToSelector:@selector(changeType:)]) {
            [_delegate changeType:CLICK_DOWN];
        }
    }
}

- (void)setUpAndDown:(BOOL)upAndDown {
    _upAndDown = upAndDown;
    if (_upAndDown) {
        _imageVI.image = [UIImage imageNamed:@"ProductList_click_up"];
    } else {
        _imageVI.image = [UIImage imageNamed:@"ProductList_click_down"];
    }
}

- (void)setCate:(HomeCategoryDetail *)cate {
    [_titleButton setTitle:cate.cat_name forState:UIControlStateNormal];
}

@end
